package com.zp.self.listener;

import com.zp.self.entity.MessageEvent;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.common.message.MessageExt;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * @author By ZengPeng
 * @Description 消息监听初始化
 * @date in  2021/3/26 11:03
 * @Modified By
 */
@Slf4j
@Component
public class ConsumerListener {

    @EventListener(condition = "#event.msgs[0].topic=='T2'")
    public void rocketmqMsgListener3(MessageEvent event) {
        List<MessageExt> msgs = event.getMsgs();
        for (MessageExt msg : msgs) {
            log.info("执行broker-a 线程名称：【" + Thread.currentThread().getName() + "】，" + new String(msg.getBody()));
        }
    }

    @EventListener(condition = "#event.msgs[0].topic=='T1'")
    public void receiveOrderMessage(MessageEvent event) {
        List<MessageExt> msgs = event.getMsgs();
        for (MessageExt msg : msgs) {
            log.info("执行broker-b 线程名称：【" + Thread.currentThread().getName() + "】，" + new String(msg.getBody()));
        }
    }

    @EventListener(condition = "#event.msgs[0].topic=='T3' && #event.msgs[0].tags=='white'")
    public void rocketmqMsgListener(MessageEvent event) {
        List<MessageExt> msgs = event.getMsgs();
        for (MessageExt msg : msgs) {
            System.err.println("线程：" + Thread.currentThread().getName() + "，消费消息:" + new String(msg.getBody()));
        }
    }
}
